package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Alt;
import org.akomantoso.core.data.attribute.CoreOpt;
import org.akomantoso.core.data.attribute.Enactment;
import org.akomantoso.core.data.attribute.HTMLattrs;
import org.akomantoso.core.data.attribute.IdOpt;
import org.akomantoso.core.data.attribute.Refers;
import org.akomantoso.core.data.attribute.XmlLang;
import org.akomantoso.core.data.type.StatusType;
import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 */
public abstract class CoreOptImpl implements CoreOpt, Externalizable {

	// from HTMLattrs
	private String _class;
	private String _style;
	private String _title;

	// from Enactment
	private StatusType _status;
	private String _period;

	// from IdOpt
	private String _id;
	private String _evolvingId;

	// from Refers
	private String _refersTo;

	// from XmlLang
	private String _xmlLang;

	// Alt
	private String _alternativeTo;

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#getClazz()
	 */
	public String getClazz() {
		return _class;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#setClazz(java.lang.String)
	 */
	public void setClazz(String clazz) {
		_class = clazz;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#getStyle()
	 */
	public String getStyle() {
		return _style;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#setStyle(java.lang.String)
	 */
	public void setStyle(String style) {
		_style = style;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#getTitle()
	 */
	public String getTitle() {
		return _title;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.HTMLattrs#setTitle(java.lang.String)
	 */
	public void setTitle(String title) {
		_title = title;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Enactment#getStatus()
	 */
	public StatusType getStatus() {
		return _status;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Enactment#setStatus(org.akomantoso.core.data.type.StatusType)
	 */
	public void setStatus(StatusType status) {
		_status = status;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Enactment#getPeriod()
	 */
	public String getPeriod() {
		return _period;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Enactment#setPeriod(java.lang.String)
	 */
	public void setPeriod(String period) {
		_period = period;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getId()
	 */
	public String getId() {
		return _id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setId(java.lang.String)
	 */
	public void setId(String id) {
		_id = id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getEvolvingId()
	 */
	public String getEvolvingId() {
		return _evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setEvolvingId(java.lang.String)
	 */
	public void setEvolvingId(String evolvingId) {
		_evolvingId = evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Refers#getRefersTo()
	 */
	public String getRefersTo() {
		return _refersTo;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Refers#setRefersTo(java.lang.String)
	 */
	public void setRefersTo(String refersTo) {
		_refersTo = refersTo;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.XmlLang#getXmlLang()
	 */
	public String getXmlLang() {
		return _xmlLang;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.XmlLang#setXmlLang(java.lang.String)
	 */
	public void setXmlLang(String xmlLang) {
		_xmlLang = xmlLang;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Alt#getAlternativeTo()
	 */
	public String getAlternativeTo() {
		return _alternativeTo;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Alt#setAlternativeTo(java.lang.String)
	 */
	public void setAlternativeTo(String alternativeTo) {
		_alternativeTo = alternativeTo;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		// from idOpt
		OutputUtil.writeIdOpt(out, this);
		// from XmlLang
		OutputUtil.writeAttribute(out, PREFIX_AND_ATTRIBUTE, _xmlLang);
		// from HTMLattrs
		OutputUtil.writeHTMLattrs(out, this);
		// from Enactment
		OutputUtil.writeEnactment(out, this);
		// from Refers
		OutputUtil.writeRefers(out, this);
		// from Alt
		OutputUtil.writeAttribute(out, Alt.ATTRIBUTE, _alternativeTo);
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		// from idOpt
		_id = in.readAttribute(IdOpt.ATTRIBUTE_ID);
		_evolvingId = in.readAttribute(IdOpt.ATTRIBUTE_EVOLVING_ID);
		// from XmlLang
		_xmlLang = in.readAttribute(XmlLang.NAMESPACE_URI,XmlLang.ATTRIBUTE);
		// from Enactment
		String temp = in.readAttribute(Enactment.ATTRIBUTE_STATUS);
		if (temp != null) {
			_status = StatusType.valueOf(temp);
		}
		_period = in.readAttribute(Enactment.ATTRIBUTE);

		// from HTMLattrs
		_class = in.readAttribute(HTMLattrs.ATTRIBUT_CLASS);
		_style = in.readAttribute(HTMLattrs.ATTRIBUT_STYLE);
		_title = in.readAttribute(HTMLattrs.ATTRIBUT_TITLE);

		// from Refers
		_refersTo = in.readAttribute(Refers.ATTRIBUTE);

		// from Alt
		_alternativeTo = in.readAttribute(Alt.ATTRIBUTE);
	}
	
}